#!/usr/bin/python

errors = {
    '200': 'Syntax error',
    '201': 'Invalid parameter',
    '205': 'Invalid user',
    '206': 'Domain name missing',
    '207': 'Already logged in',
    '208': 'Invalid username',
    '209': 'Invalid fusername',
    '210': 'User list full',
    '215': 'User already there',
    '216': 'User already on list',
    '217': 'User not online',
    '218': 'Already in mode',
    '219': 'User is in the opposite list',
    '219': 'User is in the opposite list',
    '231': 'Tried to add a contact to a group that doesn\'t exist',
    '280': 'Switchboard failed',
    '281': 'Transfer to switchboard failed',

    '300': 'Required field missing',
    '302': 'Not logged in',

    '500': 'Internal server error',
    '501': 'Database server error',
    '510': 'File operation failed',
    '520': 'Memory allocation failed',
    '540': 'Wrong CHL value sent to server',

    '600': 'Server is busy',
    '601': 'Server is unavaliable',
    '602': 'Peer nameserver is down',
    '603': 'Database connection failed',
    '604': 'Server is going down',

    '707': 'Could not create connection',
    '710': 'CVR parameters either unknown or not allowed',
    '711': 'Write is blocking',
    '712': 'Session is overloaded',
    '713': 'Too many active users',
    '714': 'Too many sessions',
    '715': 'Not expected',
    '717': 'Bad friend file',

    '911': 'Authentication failed',
    '913': 'Not allowed when offline',
    '920': 'Not accepting new users',
    '924': 'Passport account not yet verified',
}



class Error(Exception):
    """Base class for exceptions in Bumblee-bee"""
    pass

class IMError(Error):
    """Exception raised for errors in the Bumble-bee Server
    Attributes:
             errno -- The error number, which will response to client
             description -- The description of errno, used only for
                            server logging
    """
    def __init__(self, errno):
        self.errno = repr(errno)
        try:
            self.description = errors[self.errno]
        except KeyError:       # Undefine Error
            self.errno = None
            self.description = None

    def __attr__(self):
        return (self.errno, self.description)
    

if __name__ == '__main__':
    try:
        raise IMError(200)
    except IMError, e:
        print e.errno, e.description


